package com.yishu.shop.config;

import com.netflix.loadbalancer.IRule;
import com.netflix.loadbalancer.RandomRule;
import feign.Logger;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

/**
 *
 *
 * @author zengchao
 * @date 2021-07-07 20:46:39
 */
@Configuration
public class GlobalConfig {

    @LoadBalanced
    @Bean
    public RestTemplate restTemplate(){
        SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
        factory.setConnectTimeout(5 * 1000);
        factory.setReadTimeout(5 * 1000);
        return new RestTemplate(factory);
    }

    /**
     * 全局Ribbon策略
     * @return
     */
    @Bean
    public IRule ribbonRule(){
        return new RandomRule();
    }

    /**
     * 配置OpenFeign日志打印
     * @return
     */
    @Bean
    public Logger.Level openFeignLoggerLevel(){
        return Logger.Level.FULL;
    }
}
